package com.ljx.offer;

import org.junit.Test;

/**
 * @author 李捷禧
 * Date: 2023/3/15
 * ClassName: C_17
 */

public class C_17 {
    /**
     * 自己写的，就是内存占用有点大
     * @param n
     * @return
     */
    public int[] printNumbers(int n) {
        if(n == 0) return new int[0];
        int num = 0;
        for (int i = 0; i < n; i++) {
            num += 9 * powNum(10,i);
        }
        int[] arr = new int[num];
        for (int i = 0; i < num ; i++) {
            arr[i] = i+1;
        }
        return arr;
    }

    /**
     * 平方根
     * @param i
     * @param j
     * @return
     */
   int powNum(int i,int j) {
        int sum = 1;
       for (int k = 0; k < j; k++) {
           sum = sum * i;
       }
       return sum;
   }
    @Test
    public void test(){
        int[] ints = printNumbers(2);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
     //   System.out.println(powNum(5,2));
    }
}
